﻿using AiXiu.Common;
using AiXiu.DAL;
using AiXiu.IBLL;
using AiXiu.IDAL;
using AiXiu.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AiXiu.BLL
{
    public class MobileManger : IMobileManger
    {
        /// <summary>
        /// 根据手机号登录
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public OperResult<TBUsers> LoginByUserName(string mobile, string password)
        {
            //判空
            if (string.IsNullOrWhiteSpace(mobile) || string.IsNullOrWhiteSpace(password))
            {
                return OperResult<TBUsers>.Failed("手机号或者密码错误");
            }
            //通过手机号查询用户
            IMobleService service = new MobileService();
            TBLogins loginEntity = service.FindByUserMobile(mobile);
            if (loginEntity == null)
            {
                return OperResult<TBUsers>.Failed("手机号不存在!!!");
            }
            //验证用户密码
            SHAEncryption sHAEncryption = new SHAEncryption();
            if (!sHAEncryption.SHA1Encrypt(password).Equals(loginEntity.Password))
            {
                return OperResult<TBUsers>.Failed("密码错误！！");
            }
            IUersServer uersServer = new UersServer();
            TBUsers porfileEntity = uersServer.FindByUserId(loginEntity.Id);
            return OperResult<TBUsers>.Succeed(porfileEntity);
        }
    }
}
